//------------------------------------------------------------------------------
// <copyright file="HeroNameValidation.cs" company="Damian Antonowicz">
//       copyright © 2010 Damian Antonowicz
// </copyright>
// <author>Damian Antonowicz</author>
// <email>poczta@damianantonowicz.pl</email>
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Diagnostics;
using DotBeer.Business.Entities;
using DotBeer.Business.Components;

namespace DotBeer.UI.WPFClient
{
    public class HeroNameValidation : ValidationRule
    {
        HeroesCollection heroesCollection;

        public HeroNameValidation()
        {
            this.heroesCollection = HeroesCollectionComponent.Load();
        }
        
        public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
        {
            string heroName = value.ToString();

            if (this.heroesCollection.Heroes.SingleOrDefault(h => h.Name == heroName) != null)
                return new ValidationResult(true, null);
            else
                return new ValidationResult(false, "There is no such a hero");
        }
    }
}
